using System;
using System.Collections;

namespace FrameworkX.ObjectSpace
{
	/// <summary>
	/// The sole purpose of this class is to cache object schema information
	/// This is an internal class and its documentaion in not intended. This class
	/// is suppoesed to cache all state information for the database object.
	/// This is usefull when there are various threads executing in the same domain.
	/// </summary>
	internal class DatabaseGraph : IDisposable
	{				
		private Hashtable _objectDataDictionary = new Hashtable();
		private DatabaseConnection _dbConn = null;
		private int _threadID = 0;
        private Configuration _configuration = null;

		/// <summary>
		/// This is the hastable used to cache the schema for differetn types of
		/// objects
		/// </summary>
		public Hashtable ObjectDataDictionary
		{
			get{return _objectDataDictionary;}
			set{_objectDataDictionary = value;}
		}

		public DatabaseConnection Connection
		{
			get{return _dbConn;}
		}

		/// <summary>
		/// Default constructor.
		/// </summary>
		public DatabaseGraph(Configuration configuration)
		{
            _configuration = configuration;
			_dbConn = new DatabaseConnection (configuration.Provider, configuration.ConnectionString);
			_threadID = AppDomain.GetCurrentThreadId();			
		}

		public int ThreadID
		{
			get
			{
				return _threadID;
			}
		}
		#region IDisposable Members

		public void Dispose()
		{
			_objectDataDictionary.Clear();
			if( _dbConn != null )
				_dbConn.Close();

			_threadID = 0;	
		}

		#endregion
	}
}
